package com.beesphere.products.throttling;

import java.util.List;

public class EnhancedThread extends Thread {
	
	private Object context;
	private List<String> sockets;

	public EnhancedThread () {
		super ();
	}

	public EnhancedThread (Runnable target, String name) {
		super (target, name);
	}

	public EnhancedThread (Runnable target) {
		super (target);
	}

	public EnhancedThread (String name) {
		super (name);
	}

	public EnhancedThread (ThreadGroup group, Runnable target, String name,
			long stackSize) {
		super (group, target, name, stackSize);
	}

	public EnhancedThread (ThreadGroup group, Runnable target, String name) {
		super (group, target, name);
	}

	public EnhancedThread (ThreadGroup group, Runnable target) {
		super (group, target);
	}

	public EnhancedThread (ThreadGroup group, String name) {
		super (group, name);
	}

	public Object getContext() {
		return context;
	}

	public void setContext (Object context) {
		this.context = context;
	}
	
	public static Object getCurrentContext () {
		PermissionChecker.check (EnhancedThreadPermission.READ_CONTEXT);
		if (Thread.currentThread () instanceof EnhancedThread) {
        	return ((EnhancedThread)Thread.currentThread ()).getContext ();
        }
		return null;
	}

	public static void setCurrentContext (Object context) {
		PermissionChecker.check (EnhancedThreadPermission.WRITE_CONTEXT);
		if (Thread.currentThread () instanceof EnhancedThread && context != null) {
        	((EnhancedThread)Thread.currentThread ()).setContext (context);
        }
	}

	public List<String> getSockets () {
		return sockets;
	}

	public void setSockets (List<String> sockets) {
		this.sockets = sockets;
	}

}
